package com.bw.base.mvvm

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.bw.base.entity.Res
import kotlinx.coroutines.launch

open class BaseViewModel:ViewModel() {
    fun <T> httpUtils(s:suspend ()->Res<T>,success:(T)->Unit){
        try {
            viewModelScope.launch {
                val invoke = s.invoke()
                if (invoke.code==200){
                    success(invoke.data)
                }else{
                    Log.d("aaa", "httpUtils: ${invoke.message}")
                }
            }
        }catch (e:Exception){
            Log.d("aaa", "httpUtils: ${e.message}")
        }
    }
}